package cn.yunyichina.provider.clinic.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.yunyichina.provider.clinic.cache.ClinicRecordCache;
import cn.yunyichina.provider.clinic.constant.CacheConstant;
import cn.yunyichina.provider.clinic.entity.ClinicRecord;
import cn.yunyichina.provider.framework.data.AppConfig;
import cn.yunyichina.provider.framework.data.SpringContextHandler;

public class SaveAndUpdateClinicCacheRunnable implements Runnable {

	private Logger logger = LoggerFactory.getLogger(SaveAndUpdateClinicCacheRunnable.class);
	
	private String opType;

	private ClinicRecord record;
	
	public SaveAndUpdateClinicCacheRunnable() {
		super();
	}
	
	public SaveAndUpdateClinicCacheRunnable(ClinicRecord record, String opType) {
		super();
		this.record = record;
		this.opType = opType;
	}
	
	@Override
	public void run() {
		logger.info("SaveAndUpdateClinicCacheRunnable.opType : {}", opType);
		ClinicRecordCache recordCache = (ClinicRecordCache) SpringContextHandler.getBean("recordCache");
		if (CacheConstant.CACHE_OP_ADD.equals(opType) && record != null) {
			recordCache.saveRecord(record);
		} else if (CacheConstant.CACHE_OP_UPDATE.equals(opType) && record != null) {
			recordCache.updateRecord(record);
		} else if (CacheConstant.CACHE_OP_DEL.equals(opType) && record != null) {
			recordCache.deleteRecord(record);
		}
	}
	
	public String getOpType() {
		return opType;
	}

	public void setOpType(String opType) {
		this.opType = opType;
	}

	public ClinicRecord getRecord() {
		return record;
	}

	public void setRecord(ClinicRecord record) {
		this.record = record;
	}

}
